package com.example.swimfish;

public class FishData {
    private double x;
    private double y;
    private double dirX;
    private double dirY;

    private String fromHost;
    public FishData(double x, double y, double dirX, double dirY, String fromHost) {
        this.x = x;
        this.y = y;
        this.dirX = dirX;
        this.dirY = dirY;
        this.fromHost = fromHost;
    }

    // 序列化为字符串
    @Override
    public String toString() {
        return String.format("%.2f,%.2f,%.2f,%.2f,%s", x, y, dirX, dirY, fromHost);
    }

    // 从字符串反序列化
    public static FishData fromString(String data) {
        String[] parts = data.split(",");
        if (parts.length == 4) {
            return new FishData(
                    Double.parseDouble(parts[0]),
                    Double.parseDouble(parts[1]),
                    Double.parseDouble(parts[2]),
                    Double.parseDouble(parts[3]),
                    parts[4]
                    );
        }
        return null;
    }

    // Getter方法
    public double getX() { return x; }
    public double getY() { return y; }
    public double getDirX() { return dirX; }
    public double getDirY() { return dirY; }
    public String getFromHost() { return fromHost; }

}